<?php

class BaseAction extends Action
{
    public function _initialize()
    {
        $this->loadConfig();
    }

    public function loadConfig()
    {
        $tmplParseString = array();
        $this->assign('webTitle', '摩虎学院');
        $tmplParseString['__STATIC__'] = __APP__ . '/static';
        $tmplParseString['__SITE_URL__'] = __APP__;
        C('TMPL_PARSE_STRING', $tmplParseString);
    }

    /**
     * 重新设置参数
     * @param String $key 键
     * @param Mixed $value 值
     * @param bool|\Boolea $isOverlap 是否覆盖
     * @param String $partition 分隔符
     * @return string
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function reset($key, $value, $isOverlap = false, $partition = '-')
    {
        if ($key == 'webKeywords') {
            $partition = ',';
        }
        $data = $this->__get($key);
        if ($isOverlap) {
            $data = '';
        }
        if (!empty($value)) {
            if (is_string($value)) {
                if ($isOverlap) {
                    $data = $value;
                } else {
                    $data = $value . $partition . $data;
                }
            } else if (is_array($value)) {

                foreach ($value as $v) {
                    $data = $v . $partition . $data;
                }
            }
            $this->assign($key, $data);
        }
        return $data;
    }

    /**
     * 修改标题名称
     * @param $title
     */
    public function resetWebTitle($title)
    {
        $this->reset('webTitle', $title);
    }

    /**
     * 判断检查的值是否是空值
     * @param $data
     * @param $msg
     * @param null $url
     * @return
     */
    public function checkEmpty($data, $msg, $url = null, $ajax = false)
    {
        if (empty($data)) {
            if (true === $ajax || IS_AJAX) { // AJAX提交
                $this->retJson($msg);
            } else {
                $this->error($msg, $url);
            }
        }
        return $data;
    }

    /**
     * 获取分页信息
     * @param $count
     * @return string
     */
    public function getPage($count)
    {
        import('ORG.Util.Page');
        // 导入分页类
        $Page = new Page($count,C('PAGE_SIZE'));
        //$Page->setConfig('theme', ' %upPage% %first% %linkPage%  %nextPage% %prePage% %end% %downPage%  ');
        return array('limit' => $Page->firstRow . ',' . $Page->listRows, 'page' => $Page->show());
    }

    /**
     * 返回Json 数据
     * @param $data
     * @param int $info
     * @param int $status
     */
    public function retJson($data, $status = 0, $info = 0)
    {
        $this->ajaxReturn($data, $info, $status);
    }
}

?>